package com.hck.domain.health.model.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 健康檔案領域實體
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HealthProfileEntity {
    
    private Long id;
    private Long userId;
    private BigDecimal height; // 身高(cm)
    private BigDecimal weight; // 體重(kg)
    private String bloodType; // 血型
    private String allergies; // 過敏史
    private String medicalHistory; // 既往病史
    private String familyMedicalHistory; // 家族病史
    private String currentMedications; // 當前用藥情況
    private String lifestyle; // 生活方式
    private String occupation; // 職業
    private Integer maritalStatus; // 婚姻狀況
    private String educationLevel; // 教育程度
    private Date createTime;
    private Date updateTime;
    
    /**
     * 計算BMI指數
     */
    public BigDecimal calculateBMI() {
        if (height != null && weight != null && height.compareTo(BigDecimal.ZERO) > 0) {
            BigDecimal heightInMeters = height.divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
            return weight.divide(heightInMeters.multiply(heightInMeters), 2, BigDecimal.ROUND_HALF_UP);
        }
        return null;
    }
    
    /**
     * 獲取BMI等級
     */
    public String getBMILevel() {
        BigDecimal bmi = calculateBMI();
        if (bmi == null) return "未知";
        
        if (bmi.compareTo(new BigDecimal("18.5")) < 0) {
            return "偏瘦";
        } else if (bmi.compareTo(new BigDecimal("24")) <= 0) {
            return "正常";
        } else if (bmi.compareTo(new BigDecimal("28")) <= 0) {
            return "超重";
        } else {
            return "肥胖";
        }
    }
}